namespace IAM.Interface.Common.Providers
{
    using System;
    using System.IO;
    using System.Net;
    using System.Text;

    public class SAPProvider : IProvider
    {
        public SAPProvider(string url, string sendstring)
        {
            base._url = url;
            base._sendstring = sendstring;
        }

        public override string GetResponseStr()
        {
            string str = "";
            try
            {
                byte[] bs = Encoding.ASCII.GetBytes("xml=" + base._sendstring);
                HttpWebRequest httpRequest = (HttpWebRequest) WebRequest.Create(base._url);
                httpRequest.Method = "post";
                httpRequest.ContentType = "text/xml";
                httpRequest.ContentLength = bs.Length;
                using (Stream reqStream = httpRequest.GetRequestStream())
                {
                    reqStream.Write(bs, 0, bs.Length);
                    reqStream.Flush();
                }
                HttpWebResponse httpResponse = (HttpWebResponse) httpRequest.GetResponse();
                if (httpRequest.HaveResponse)
                {
                    StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), Encoding.Default);
                    str = sr.ReadToEnd();
                    sr.Close();
                    httpResponse.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return str;
        }
    }
}

